# 1041. 困于环中的机器人/GLL模拟
class Solution:
  def isRobotBounded(self, instructions: str) -> bool:
    direct = 0
    x = 0
    y = 0
    for char in instructions:
      if char == 'G':
        if direct == 0:
          y += 1
        elif direct == 1:
          x -= 1
        elif direct == 2:
          y -= 1
        else:
          x += 1
      elif char == 'L':
        direct = (direct + 1) % 4
      else:
        direct = (direct + 3) % 4
    return (x == 0 and y == 0) or direct != 0

if __name__ == '__main__':
  Solution().isRobotBounded("GL")

